<?php
	require_once (dirname(__FILE__)."/../../config/Config.inc");
	require_once (dirname(__FILE__)."/../../config/api.inc");
	require_once ("load.php");
	
	$parm = requestArrayParm($_REQUEST);
	
	$result['status'] = '0';
	
	if($parm['m'] == 'myZR')
	{
		unset($query);
		$query['uid'] = $userinfo['id'];
		$zrinfo = _SqlTool::getInfo('zhuanrang',$query);
		if(!empty($zrinfo))
		{
			$result['status'] = '1';
			$zrinfo['tztime'] = date('Y-m-d',$zrinfo['tztime']);
			$zrinfo['dqtime'] = date('Y-m-d',$zrinfo['dqtime']);
			$result['info'] = $zrinfo;
		}
		$result['info'] = $zrinfo;
	}
	
	
	if($parm['m'] == 'save')
	{
		unset($query);
		$query['uid'] = $userinfo['id'];
		$zrinfo = _SqlTool::getInfo('zhuanrang',$query);
		if(!empty($zrinfo))
		{
			unset($query,$data);
			$query['id'] = $zrinfo['id'];
			$data['pt_name'] = $parm['pt_name'];
			$data['tztime'] = strtotime($parm['tztime']);
			$data['dqtime'] = strtotime($parm['dqtime']);
			$data['tzmoney'] =  floatval($parm['tzmoney']);
			$data['zrmoney'] = floatval($parm['zrmoney']);
			$data['sale'] = round(floatval($data['zrmoney']) / floatval($data['tzmoney']),2);
			$data['fbtime'] = time();
			$res = _SqlTool::setInfo('zhuanrang', $query, $data);
		}
		else
		{
			unset($data);
			
			$data['uid'] = $userinfo['id'];
			
			$data['phone'] = $userinfo['loginname'];
			$data['name'] = $userinfo['name'];
			
			$data['pt_name'] = $parm['pt_name'];
			$data['tztime'] = strtotime($parm['tztime']);
			$data['dqtime'] = strtotime($parm['dqtime']);
			$data['tzmoney'] =  floatval($parm['tzmoney']);
			$data['zrmoney'] = floatval($parm['zrmoney']);
			$data['sale'] = round(floatval($data['zrmoney']) / floatval($data['tzmoney']),2);
			$data['fbtime'] = time();
			$data['status'] = '1';
			
			$res = _SqlTool::addInfo('zhuanrang', $data);
		}
		
		if($res)
		{
			$result['status'] = '1';
			$result['msg'] = '成功';
		}
		else
		{
			$result['msg'] = '失败';
		}
		
	}
	
	echoJSON($result);